<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru"> 
    <head>
	<title>LocalCRM</title>
	<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="js/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
	<script src="js/jquery.blockUI.js" type="text/javascript"></script>
	<script src="js/jquery.contextMenu.js" type="text/javascript"></script>

	<script src="js/i18n/grid.locale-ru.js" type="text/javascript"></script>
	<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
	<link href="css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>

	<script src="js/crm/common.js" type="text/javascript"></script>
	<link href="css/redmond/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>
	<link href="css/jquery.contextMenu.css" rel="stylesheet" type="text/css"/>
    </head>
    <body style="display:none;">
	<script type="text/javascript">
	<!--
	{literal}
	$(document).ready
	(
	    function()
	    {
		$('#match-jur').click
		(
		    function()
		    {
			if ( $(this).attr('checked') )
			{
			    $('#actual-region').val( $('#legal-region').val() );
			    $('#actual-city').val( $('#legal-city').val() );
			    $('#actual-index').val( $('#legal-index').val() );
			    $('#actual-street').val( $('#legal-street').val() );
			    $('#actual-home').val( $('#legal-home').val() );
			    $('#actual-litera').val( $('#legal-litera').val() );
			    $('#actual-office').val( $('#legal-office').val() );

			    $('.address-actual').hide();
			}
			else
			{
			    $('.address-actual')
				.val('')
				.show();
			}
		    }
		);

		$('#match').click
		(
		    function()
		    {
			if ( $(this).attr('checked') )
			{
			    $('#postal-match')
				.fadeIn('fast')
				.focus();
			}
			else
			{
			    $('#postal-match').fadeOut('fast');
			    $('.address-postal:hidden').show();
			}
		    }
		);

		$('#postal-match').change
		(
		    function()
		    {
			if ( $('#match').attr('checked') )
			{
			    switch($(this).val())
			    {
				case	'jur':
				    $('#postal-region').val( $('#legal-region').val() );
				    $('#postal-city').val( $('#legal-city').val() );
				    $('#postal-index').val( $('#legal-index').val() );
				    $('#postal-street').val( $('#legal-street').val() );
				    $('#postal-home').val( $('#legal-home').val() );
				    $('#postal-litera').val( $('#legal-litera').val() );
				    $('#postal-office').val( $('#legal-office').val() );
				    $('.address-postal').hide();
				    break;

				case	'act':
				    $('#postal-region').val( $('#actual-region').val() );
				    $('#postal-city').val( $('#actual-city').val() );
				    $('#postal-index').val( $('#actual-index').val() );
				    $('#postal-street').val( $('#actual-street').val() );
				    $('#postal-home').val( $('#actual-home').val() );
				    $('#postal-litera').val( $('#actual-litera').val() );
				    $('#postal-office').val( $('#actual-office').val() );
				    $('.address-postal').hide();
				    break;

				case	'0':
				    $('#match').attr('checked',false);
				    $(this).fadeOut('fast');
				    $('.address-postal')
					.val('')
					.show();
			    }
			}
		    }
		);

		$('input:button#clear').click(function(){$('input:text').val('')});
		$('input:button#save').click
		(
		    function()
		    {
			$('form#main').submit();
		    }
		);

		$('input[id$=region]').autocomplete
		({
		    source:	'json/getDictionary.php?dictionary=regions',
		    delay:	0
		});

		$('input[id$=city]').autocomplete
		({
		    source:	'json/getDictionary.php?dictionary=cities',
		    delay:	0
		});

		$('input[id$=street]').autocomplete
		({
		    source:	'json/getDictionary.php?dictionary=streets',
		    delay:	0
		});

		$('input#contact-post').autocomplete
		({
		    source:	'json/getDictionary.php?dictionary=posts',
		    delay:	0
		});

		$('a#manage-managers').click
		(
		    function()
		    {
			refreshManagers();
			$('div#managers')
			    .dialog('option','title','Менеджеры')
			    .dialog('option','resizable',false)
			    .dialog('option','width',750)
			    .dialog('open');
		    }
		);

		$('a#manage-groups').click
		(
		    function()
		    {
			refreshGroups();
			$('div#groups')
			    .dialog('option','title','Управление группами')
			    .dialog('option','resizable',false)
			    .dialog('option','width',320)
			    .dialog('open');
		    }
		);

		$('a#manage-statuses').click
		(
		    function()
		    {
			refreshStatuses();
			$('div#statuses')
			    .dialog('option','title','Управление статусами')
			    .dialog('option','resizable',false)
			    .dialog('option','width',320)
			    .dialog('open');
		    }
		);

		$('a#manager-add').click
		(
		    function()
		    {
			var tbody = $('div#managers').find('tbody');
			var last_num = tbody.children(':last').children().html();
			var link = $(this);
			tbody
			    .append
			    (
				'<tr>'
				    +'<td>'+(parseFloat(last_num)+1)+'</td>'
				    +'<td><input type="text" id="manager-name"/></td>'
				    +'<td><input type="text" id="manager-login"/></td>'
				    +'<td><input type="text" id="manager-password"/>&nbsp;<a href="javascript:void(0)" id="manager-password-generate"><img src="images/icons/key_16.png" border="0" title="Сгенерировать пароль"/></a></td>'
				    +'<td align="center"><input type="checkbox" id="manager-admin"/></td>'
				    +'<td align="center"><a href="javascript:void(0)" id="manager-save"><img src="images/icons/tick_16.png" border="0"/></a></td>'
				+'</tr>'
			    )
			    .find('a#manager-save')
				.click
				(
				    function()
				    {
					$.ajax
					({
					    cache:	false,
					    url:	'json/manager.php',
					    type:	'POST',
					    dataType:	'json',
					    data:
					    {
						action:	'add',
						manager_name:	$('input#manager-name').val(),
						login:		$('input#manager-login').val(),
						password:	$('input#manager-password').val(),
						int_num:	$('input#manager-int-num').val(),
						is_admin:	$('input#manager-admin').attr('checked')?1:0,
					    },
					    success:	function(json)
					    {
						switch(json['code'])
						{
						    case	200:
							refreshManagers();
							link.fadeIn();
							break;
						    default:
							alert(json['text']);
						}
					    }
					});
				    }
				)
				.end()
			    .find('a#manager-password-generate')
				.click
				(
				    function()
				    {
					$.getJSON('json/getRandomPassword.php',function(json){$('#manager-password').val(json['pw']);});
				    }
				);

			$(this).fadeOut();
		    }
		);

		$('a#password-generate').click(function(){$.getJSON('json/getRandomPassword.php',function(json){$('input#email-password').val(json['pw']);});});

		function refreshManagers()
		{
		    $.getJSON
		    (
			'json/getDictionary.php',
			{ dictionary: 'managers' },
			function(json)
			{
			    var select= $('select#manager-select');
			    var tbody = $('div#managers').find('tbody');
			    tbody.find('tr').remove();
			    select.find('option').remove();

			    for(i=0;i<json.length;i++)
			    {
				select
				    .append('<option value="'+json[i]['id']+'">'+json[i]['manager_name']+'</option>')
				    .find('option[value='+json[i]['id']+']')
					.attr('selected',json[i]['id']=={/literal}{$session.manager.id}{literal}?true:false);

				tbody
				    .append
				    (
					'<tr id="manager_'+json[i]['id']+'">'
					    +'<td>'+(i+1)+'</td>'
					    +'<td>'+json[i]['manager_name']+'</td>'
					    +'<td>'+json[i]['login']+'</td>'
					    +'<td>'+json[i]['password']+'</td>'
					    +'<td align="center"><input type="checkbox" class="manager-is-admin"/></td>'
					    +'<td>'+json[i]['internal_number']+'</td>'
					    +'<td align="center"><a href="javascript:void(0)" class="manager-delete"><img src="images/icons/delete_16.png" border="0" title="Удалить"/></a></td>'
					+'</tr>'
				    )
				    .find('tr#manager_'+json[i]['id'])
					.find('input:checkbox.manager-is-admin')
					    .attr('checked',json[i]['is_admin']=='1'?true:false)
					    .click
					    (
						function()
						{
						    var manager_id = $(this).parent().parent().attr('id');
						    $.ajax
						    ({
							cache:	false,
							url:	'json/manager.php',
							type:	'POST',
							dataType:	'json',
							data:
							{
							    action:	'update',
							    is_admin:	$(this).attr('checked')?1:0,
							    id:	manager_id
							},
							success:	function(json)
							{
							    switch(json['code'])
							    {
								case	200:
								    refreshManagers();
								    break;
								default:
								    alert(json['text']);
							    }
							}
						    });
						}
					    )
					    .end()
					.find('a.manager-delete')
					    .click
					    (
						function()
						{
						    var manager_id = $(this).parent().parent().attr('id');
						    $.ajax
						    ({
							cache:	false,
							url:	'json/manager.php',
							type:	'POST',
							dataType:	'json',
							data:
							{
							    action:	'delete',
							    id:	manager_id
							},
							success:	function(json)
							{
							    switch(json['code'])
							    {
								case	200:
								    refreshManagers();
								    break;
								default:
								    alert(json['text']);
							    }
							}
						    });
						}
					    )
					    .end();
			    }
			}
		    )
		}

		$('a#group-add').click
		(
		    function()
		    {
			var tbody = $('div#groups').find('tbody');
			var last_num = tbody.children(':last').children().html();
			var link = $(this);
			tbody
			    .append
			    (
				'<tr>'
				    +'<td>'+(parseFloat(last_num)+1)+'</td>'
				    +'<td><input type="text" id="group-name"/></td>'
				    +'<td align="center"><a href="javascript:void(0)" id="group-save"><img src="images/icons/tick_16.png" border="0"/></a></td>'
				+'</tr>'
			    )
			    .find('a#group-save')
				.click
				(
				    function()
				    {
					$.getJSON
					(
					    'json/updateDictionary.php',
					    {
						dictionary:	'groups',
						action:		'add',
						name:		$('input#group-name').val()
					    },
					    function(json)
					    {
						switch(json['code'])
						{
						    case	200:
							refreshGroups();
							link.fadeIn();
							break;
						    default:
							alert(json['text']);
						}
					    }
					);
				    }
				);
			$(this).fadeOut();
		    }
		);

		function refreshGroups()
		{
		    $.getJSON
		    (
			'json/getDictionary.php',
			{ dictionary: 'groups' },
			function(json)
			{
			    var select= $('select#select-group');
			    var tbody = $('div#groups').find('tbody');
			    tbody.find('tr').remove();
			    select.find('option').remove();

			    for(i=0;i<json.length;i++)
			    {
				select
				    .append('<option value="'+json[i]['id']+'">'+json[i]['group_name']+'</option>');

				tbody
				    .append
				    (
					'<tr id="group_'+json[i]['id']+'">'
					    +'<td>'+(i+1)+'</td>'
					    +'<td>'+json[i]['group_name']+'</td>'
					    +'<td align="center"><a href="javascript:void(0)" class="group-delete"><img src="images/icons/delete_16.png" border="0" title="Удалить"/></a></td>'
					+'</tr>'
				    )
				    .find('tr#group_'+json[i]['id'])
					.find('a.group-delete')
					    .click
					    (
						function()
						{
						    var id = $(this).parent().parent().attr('id');
						    $.getJSON
						    (
							'json/updateDictionary.php',
							{
							    dictionary:	'groups',
							    action:	'delete',
							    id:		id
							},
							function(json)
							{
							    switch(json['code'])
							    {
								case	200:
								    refreshGroups();
								    break;
								default:
								    alert(json['text']);
							    }
							}
						    );
						}
					    )
					    .end();
			    }
			}
		    )
		}

		$('a#status-add').click
		(
		    function()
		    {
			var tbody = $('div#statuses').find('tbody');
			var last_num = tbody.children(':last').children().html();
			var link = $(this);
			tbody
			    .append
			    (
				'<tr>'
				    +'<td>'+(parseFloat(last_num)+1)+'</td>'
				    +'<td><input type="text" id="status-name"/></td>'
				    +'<td align="center"><a href="javascript:void(0)" id="status-save"><img src="images/icons/tick_16.png" border="0"/></a></td>'
				+'</tr>'
			    )
			    .find('a#status-save')
				.click
				(
				    function()
				    {
					$.getJSON
					(
					    'json/updateDictionary.php',
					    {
						dictionary:	'statuses',
						action:		'add',
						name:		$('input#status-name').val()
					    },
					    function(json)
					    {
						switch(json['code'])
						{
						    case	200:
							refreshStatuses();
							link.fadeIn();
							break;
						    default:
							alert(json['text']);
						}
					    }
					);
				    }
				);
			$(this).fadeOut();
		    }
		);

		function refreshStatuses()
		{
		    $.getJSON
		    (
			'json/getDictionary.php',
			{ dictionary: 'statuses' },
			function(json)
			{
			    var select= $('select#select-status');
			    var tbody = $('div#statuses').find('tbody');
			    tbody.find('tr').remove();
			    select.find('option').remove();

			    for(i=0;i<json.length;i++)
			    {
				select
				    .append('<option value="'+json[i]['id']+'">'+json[i]['status_name']+'</option>');

				tbody
				    .append
				    (
					'<tr id="status_'+json[i]['id']+'">'
					    +'<td>'+(i+1)+'</td>'
					    +'<td>'+json[i]['status_name']+'</td>'
					    +'<td align="center"><a href="javascript:void(0)" class="status-delete"><img src="images/icons/delete_16.png" border="0" title="Удалить"/></a></td>'
					+'</tr>'
				    )
				    .find('tr#status_'+json[i]['id'])
					.find('a.status-delete')
					    .click
					    (
						function()
						{
						    var id = $(this).parent().parent().attr('id');
						    $.getJSON
						    (
							'json/updateDictionary.php',
							{
							    dictionary:	'statuses',
							    action:	'delete',
							    id:		id
							},
							function(json)
							{
							    switch(json['code'])
							    {
								case	200:
								    refreshStatuses();
								    break;
								default:
								    alert(json['text']);
							    }
							}
						    );
						}
					    );
			    }
			}
		    )
		}

		$('tr.task-row')
		    .css('cursor','pointer')
		    .hover
		    (
			function(){$(this).addClass('ui-state-hover');},
			function(){$(this).removeClass('ui-state-hover');}
		    )
		    .click(function(){showTask($(this).children().children().html());});

		$('a.contact-delete').click
		(
		    function()
		    {
			if ( !window.confirm('Вы уверены?') )
			{
			    return false;
			}
		    }
		);

		$('a#treatment-add').click
		(
		    function()
		    {
			$('div#treatment')
			    .dialog('option','title','Добавить обращение')
			    .dialog('option','width',700)
			    .dialog('option','resizable',false)
			    .dialog('option','buttons',{'Сохранить':function(){$(this).find('form').submit();}})
			    .dialog('open');
		    }
		);

		$('a#contact-add').click
		(
		    function()
		    {
			$('div#contact')
			    .dialog('option','title','Добавить контакт')
			    .dialog('option','width',480)
			    .dialog('option','resizable',false)
			    .dialog('option','buttons',{'Сохранить':function(){$(this).find('form').submit();}})
			    .dialog('open');
		    }
		);

		$('a#contract-add').click
		(
		    function()
		    {
			var new_row = $('tr.contract-row:last')
			    .clone()
			    .find('input')
				.val('')
				.end();

			$('tr.contract-row:last').after(new_row);
		    }
		);

		$('a#arbitrary-add').click
		(
		    function()
		    {
			var new_row = $('tr.arbitrary-row:last')
			    .clone()
			    .find('input')
				.val('')
				.end();

			$('tr.arbitrary-row:last').after(new_row);
		    }
		);

		$('#document-add').click
		(
		    function()
		    {
			$('div#docs')
			    .dialog('option','title','Добавить документы')
			    .dialog('option','width','auto')
			    .dialog('option','resizable',false)
			    .dialog('option','buttons',{'Загрузить':function(){$(this).find('form').submit();}})
			    .dialog('open');
		    }
		);

		$('#document-add-invoice').click
		(
		    function()
		    {
			$('div#docs-invoice')
			    .dialog('option','title','Добавить документы')
			    .dialog('option','width','auto')
			    .dialog('option','resizable',false)
			    .dialog('option','buttons',{'Загрузить':function(){$(this).find('form').submit();}})
			    .dialog('open');
		    }
		);

		$('#document-append').click
		(
		    function()
		    {
			$('div#docs')
			    .find('tbody')
				.find('tr:last')
				.clone()
				.find('input')
				    .val('')
				    .end()
				.appendTo($('div#docs').find('tbody'));
		    }
		);

		$('#document-append-invoice').click
		(
		    function()
		    {
			$('div#docs-invoice')
			    .find('tbody')
				.find('tr:last')
				.clone()
				.find('input')
				    .val('')
				    .end()
				.appendTo($('div#docs-invoice').find('tbody'));
		    }
		);

		$('a#act-print-rtk').click
		(
		    function()
		    {
			window.open('doc-print.php?type=akt&provider=rtk&account_id={/literal}{$customer.account_id}{literal}','DOC');
		    }
		);

		$('a#act-print-inline').click
		(
		    function()
		    {
			window.open('doc-print.php?type=akt&provider=inline&account_id={/literal}{$customer.account_id}{literal}','DOC');
		    }
		);

		$('a#invoice-print-rtk').click
		(
		    function()
		    {
			window.open('doc-print.php?type=invoice&provider=rtk&account_id={/literal}{$customer.account_id}{literal}','DOC');
		    }
		);

		$('a#invoice-print-inline').click
		(
		    function()
		    {
			window.open('doc-print.php?type=invoice&provider=inline&account_id={/literal}{$customer.account_id}{literal}','DOC');
		    }
		);

		$('#task').click
		(
		    function()
		    {
			if ( $(this).attr('checked') )
			{
			    $('tr.task-prop').show();
			}
			else
			{
			    $('tr.task-prop').hide();
			}
		    }
		);

		$('div.dialog#context')
		    .dialog
		    (
			'option',
			{
			    title:	'Редактирование',
			    width:	1000,
			    resizable:	false,
			    position: [250,50]
			}
		    );

		$('tr.data-row')
		    .css('cursor','default')
		    .contextMenu
		    (
			{ menu:	'contextMenu-common' },
			function(action,el,pos)
			{
			    var Class = $(el)
					    .parentsUntil('table')
					    .parent()
					    .attr('id');

			    var obj_id= $(el)
					    .children()
					    .children()
					    .html();

			    switch(action)
			    {
				case	'edit':
				    $.get(Class+'.php',{id:$(el).children().children().html()},function(data){$('div#context').html(data);});
				    $('div#context')
					.text('Загрузка...')
					.dialog('open');
				    break;

				case	'delete':
				    if ( window.confirm('Вы уверены?') )
				    {
					window.location = Class+'-delete.php?id='+obj_id;
				    }
				    break;
			    }
			}
		    );

		$('div.ui-state-disabled')
		    .find('input:text,input:submit,select')
			.attr('disabled',true);

		$('input:checkbox.set-period').click
		(
		    function()
		    {
			if ( $(this).attr('checked') )
			{
			    $('div.div-set-period')
				.addClass('ui-state-default')
				.removeClass('ui-state-disabled')
				.find('input,select')
				    .attr('disabled',false);
			}
			else
			{
			    $('div.div-set-period')
				.addClass('ui-state-disabled')
				.removeClass('ui-state-default')
				.find('input:text,input:submit,select')
				    .attr('disabled',true)
				    .end()
				.find('form')
				    .submit();
			}
		    }
		);

		$('a#customer-reorder')
		    .click
		    (
			function()
			{
			    if ( !window.confirm("ВНИМАНИЕ! Переоформление приведёт к удалению (блокировке) текущего клиента!\nПродолжить?") )
			    {
				return false;
			    }
			}
		    );
	    }
	);
	{/literal}
	-->
	</script>

{if not empty($customer.is_deleted)}
	<script type="text/javascript">
	<!--{literal}
	$(document).ready
	(
	    function()
	    {
		$('td#customer-data')
		    .find('input,select,textarea')
			.attr('disabled',true)
			.unbind()
			.end()

		    .find('a[href^=javascript]')
			.addClass('ui-state-disabled')
			.unbind()
			.end()

		    .find('a[href*="\.php"],a[href^=?]')
			.attr('href','javascript:void(0)')
			.addClass('ui-state-disabled')
			.unbind();
	    }
	);
	{/literal}-->
	</script>
{/if}

<!-- НАЧАЛО контекстного меню -->
	<ul id="contextMenu-common" class="ui-widget" style="display: none;">
	    <li class="edit"><a href="#edit">Изменить</a></li>
	    <li class="delete"><a href="#delete">Удалить</a></li>
	</ul>
<!-- КОНЕЦ контекстного меню -->

	<div class="dialog" id="context"></div>

<!--
/*
#    НАЧАЛО БЛОКА ВСПЛЫВАЮЩИХ ОКОН
*/
-->

<!-- Инфо о задаче -->
	<div id="task-info" class="dialog">
	    <table width="100%" class="ui-widget ui-state-default" cellspacing="0">
		<thead>
		    <tr>
			<td align="right"><strong>Постановщик:</strong></td>
			<td></td>
			<td align="right"><strong>Дата постановки:</strong></td>
			<td></td>
		    </tr>
		    <tr>
			<td align="right"><strong>Ответственный:</strong></td>
			<td></td>
			<td align="right"><strong>Приступить к выполнению:</strong></td>
			<td></td>
		    </tr>
		</thead>
		<tbody>
		</tbody>
	    </table>
	</div>

<!-- Список сотрудников -->
	<div class="dialog" id="managers">
	    <table width="100%" class="ui-widget" cellspacing="0" rules="all" style="border: solid 1px #000000;">
		<thead class="ui-widget-header">
		    <tr>
			<th>#</th>
			<th>Имя</th>
			<th>Логин</th>
			<th>Пароль</th>
			<th>Админ</th>
			<th>Внутр. номер</th>
			<th>&nbsp;</th>
		    </tr>
		</thead>
		<tbody class="ui-widget-content">
		</tbody>
	    </table>
	    <br/>
	    <a href="javascript:void(0)" id="manager-add"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Добавить менеджера</a>
	</div>

<!-- Список групп -->
	<div class="dialog" id="groups">
	    <table width="100%" class="ui-widget" cellspacing="0" rules="all" style="border: solid 1px #000000;">
		<thead class="ui-widget-header">
		    <tr>
			<th>#</th>
			<th>Имя</th>
			<th>&nbsp;</th>
		    </tr>
		</thead>
		<tbody class="ui-widget-content">
		</tbody>
	    </table>
	    <br/>
	    <a href="javascript:void(0)" id="group-add"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Добавить группу</a>
	</div>

<!-- Список статусов -->
	<div class="dialog" id="statuses">
	    <table width="100%" class="ui-widget" cellspacing="0" rules="all" style="border: solid 1px #000000;">
		<thead class="ui-widget-header">
		    <tr>
			<th>#</th>
			<th>Имя</th>
			<th>&nbsp;</th>
		    </tr>
		</thead>
		<tbody class="ui-widget-content">
		</tbody>
	    </table>
	    <br/>
	    <a href="javascript:void(0)" id="status-add"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Добавить статус</a>
	</div>

	{if $customer!=''}
<!-- Добавление обращений -->
	<div class="dialog" id="treatment">
	    <form action="db.php" method="post">
	    <input type="hidden" name="action" value="treatment.new.do"/>
	    <input type="hidden" name="account_id" value="{$customer.account_id}" id="account-id"/>
	    <table class="ui-widget" cellspacing="0" width="100%">
		<tr>
		    <td align="right">Тип:</td>
		    <td>
			<select name="direction">
			    <option value="incomming">Входящее</option>
			    <option value="outgoing">Исходящее</option>
			</select>
		    </td>
		    <td colspan="2">
			<input type="checkbox" name="task" id="task"/>
			<label for="task" style="corsor: pointer;">Задача</label>
		    </td>
		</tr>
		<tr>
		    <td align="right">Дата:</td>
		    <td><input type="text" name="treatment_date" class="date"/></td>
		    <td align="right">Время:</td>
		    <td>{html_select_time display_seconds=false}</td>
		</tr>
		<tr>
		    <td align="right" valign="top">Примечание:</td>
		    <td colspan="3"><textarea name="note" style="width: 100%;"></textarea></td>
		</tr>
		<tr>
		</tr>
		<tr class="task-prop" style="display: none;">
		    <td align="right">Приступить:</td>
		    <td><input type="text" name="start_date" class="date"/>&nbsp;{html_select_time prefix=start_ display_seconds=false minute_interval=10}</td>
		    <td align="right">Ответственный:</td>
		    <td>
			<select name="responsible_manager">
			{foreach from=$managers item=manager}
			    <option value="{$manager.id}" {if $session.manager.id==$manager.id}selected{/if}>{$manager.manager_name}</option>
			{/foreach}
			</select>
		    </td>
		</tr>
	    </table>
	    </form>
	</div>

<!-- Добавление контакта -->
	<div class="dialog" id="contact">
	    <form action="db.php" method="post">
	    <input type="hidden" name="action" value="contact.new.do"/>
	    <input type="hidden" name="account_id" value="{$customer.account_id}"/>
	    <table class="ui-widget" cellspacing="0" width="100%">
		<tr>
		    <td align="right">ФИО:</td>
		    <td><input type="text" name="contact_name"/></td>
		</tr>
		<tr>
		    <td align="right">Должность:</td>
		    <td><input type="text" name="post" id="contact-post"/></td>
		</tr>
		<tr>
		    <td align="right">Телефон:</td>
		    <td><input type="text" name="phone_number"/></td>
		</tr>
		<tr>
		    <td align="right">E-Mail:</td>
		    <td><input type="text" name="email"/></td>
		</tr>
		<tr>
		    <td align="right" valign="top">Примечание:</td>
		    <td><textarea name="note"></textarea></td>
		</tr>
	    </table>
	    </form>
	</div>

{* Добавление услуги *}
{include file="admin/submodules/service_add.module.html"}

<!-- Загрузка документа -->
	<div class="dialog" id="docs">
	    <form action="upload.php" method="post" enctype="multipart/form-data">
		<input type="hidden" name="account_id" value="{$customer.account_id}"/>
		<table width="98%" align="center">
		    <thead>
			<tr>
			    <th>Номер документа</th>
			    <th>Название документа</th>
			    <th>Дата</th>
			    <th>Файл</th>
			</tr>
		    </thead>
		    <tbody>
			<tr>
			    <td><input type="text" name="document_num[]"/></td>
			    <td><input type="text" name="document_name[]"/></td>
			    <td><input type="text" name="document_date[]" class="date"/></td>
			    <td><input type="file" name="document_file[]"/></td>
			</tr>
		    </tbody>
		</table>
		<a href="javascript:void(0)" id="document-append"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Добавить файл</a>
	    </form>
	    <br/>
	    <small>* Примечание: Максимальный размер одного файла: {$upload_max_filesize}</small>
	</div>

<!-- Загрузка счёта -->
	<div class="dialog" id="docs-invoice">
	    <form action="upload.php" method="post" enctype="multipart/form-data">
		<input type="hidden" name="account_id" value="{$customer.account_id}"/>
		<table width="98%" align="center">
		    <thead>
			<tr>
			    <th>Номер документа</th>
			    <th>Название документа</th>
			    <th>Дата</th>
			    <th>Тип</th>
			    <th>Файл</th>
			</tr>
		    </thead>
		    <tbody>
			<tr>
			    <td><input type="text" name="document_num[]"/></td>
			    <td><input type="text" name="document_name[]"/></td>
			    <td><input type="text" name="document_date[]" class="date"/></td>
			    <td>
				<select name="type[]">
				    <option value="inv_region">Регион Телеком</option>
				    <option value="inv_inlain">Инлайн</option>
				</select>
			    </td>
			    <td><input type="file" name="document_file[]"/></td>
			</tr>
		    </tbody>
		</table>
		<a href="javascript:void(0)" id="document-append-invoice"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Добавить файл</a>
	    </form>
	    <br/>
	    <small>* Примечание: Максимальный размер одного файла: {$upload_max_filesize}</small>
	</div>
	{/if}

<!--
/*
#    НАЧАЛО HTML-ТЕЛА СТРАНИЦЫ
*/
-->
	<table width="100%">
	    <tr>
<!-- Левое навигационное меню -->
		<td width="15%" align="center" valign="top" style="padding: 1em;">
		    <a href="admin.php" class="button">Основное меню</a>
		    <hr/>
{if empty($customer.is_deleted)}
		    <a href="?action=customer.new&parent_id={$customer.id}" class="button" id="customer-reorder">Переоформить</a>
    {if is_numeric($customer.parent)}
		    <div style="margin-top: 20px; border: dashed 1px #000; padding: 1em;">
			<strong>Переоформленный клиент</strong>
			<hr/>
			<a href="customer-view.php?id={$customer.parent}" class="button">{$customer.parent_name|default:'Родитель'}</a>
		    </div>
    {/if}
		    <div style="margin-top: 300px;">
			<input type="button" class="button" id="save" value="Сохранить"/><br/>
			<input type="button" class="button" id="clear" value="Очистить"/><br/>
		    </div>
{else}
		    <div style="margin-top: 20px; border: dashed 1px #000; padding: 1em;">
			<strong style="color:#f00;">УДАЛЕН</strong>
{*
			<hr/>
			<a href="javascript:void(0)" class="button">Отменить удаление</a>
*}
		    </div>
{/if}
		</td>
		<td valign="top" id="customer-data">
		{if $customer!=''}
		    <input type="hidden" name="id" id="customer-id" value="{$customer.id}"/>
		    {if not empty($smarty.session.options)}
		    <input type="hidden" id="last-tab-id" value="{$smarty.session.options.customerView[$smarty.get.id].tab}"/>
		    </pre>
		    {/if}
		{/if}
<!--
/*
#    НАЧАЛО ВКЛАДОК
*/
-->
{foreach from=$smarty.session.options.tabs item=tab key=tabName}
    {if $tab[$tabName]>0}
		    <input type="hidden" class="tabIndex" name="{$tabName}" value="{$tab[$tabName]}"/>
    {/if}
{/foreach}

		    <script type="text/javascript">
		    <!--{literal}
		    $(document).ready
		    (
			function()
			{
			    $('input.tabIndex').each
			    (
				function()
				{
				    $('div.tabs#'+$(this).attr('name')).tabs('select',parseFloat($(this).val()));
				}
			    );
			}
		    );
		    {/literal}-->
		    </script>

		    <div class="tabs" id="customerInfo">
<!-- Список (меню) вкладок -->
			<ul>
			    <li><a href="#info">Карточка</a></li>
			    <li><a href="#bank">Реквизиты</a></li>
			    {if $customer!=''}
			    <li><a href="#services">Услуги</a></li>
			    <li><a href="#contact">Контакты</a></li>
			    {/if}
			    {if $customer!=''}
			    <li><a href="#document">Документы</a></li>
			    <li><a href="#invoice">Счета</a></li>
				{if $contracts|@count>0}
			    <li><a href="#payment">Оплата</a></li>
			    <li><a href="#verification-act">Акты сверки</a></li>
				{/if}
			    {/if}
			</ul>
<!-- ВКЛАДКА Основная карточка -->
			<div id="info">
			    <form method="post" action="db.php" id="main">
			    <input type="hidden" name="action" value="{if $customer!=''}customer.edit.do{else}customer.new.do{/if}"/>
			    {if $customer!=''}<input type="hidden" name="id" value="{$customer.id}"/>{/if}

			    <table align="left" class="ui-widget">
				<tr>
				    <td align="left">Клиент:</td>
				    <td colspan="12" align="left"><input align="left" type="text" name="name" value="{$customer.customer_name|sslash|escape}" style="width: 100%"/></td>
				</tr>
				{foreach from=$contracts item=contract}
				<tr class="contract-row">
				    <td align="left">Номер договора:</td>
				    <td><input size="10" type="text" name="contract_num_{$contract.id}" value="{$contract.contract_number}"/></td>
				    <td>Баланс:</td>
				    <td>{$contract.balance}</td>
				    <td>Аванс:</td>
				    <td><input type="text" size="10" name="prepayment_{$contract.id}" value="{$contract.prepayment}"/></td>
				    <td>Дата заключения:</td>
				    <td><input type="text" name="date_contract_{$contract.id}" class="date" value="{$contract.accepted_date|date_format:'%Y-%m-%d'}"/></td>
				    <td>Дата окончания:</td>
				    <td><input type="text" name="date_contract_end_{$contract.id}" class="date" value="{$contract.end_date|date_format:'%Y-%m-%d'}"/></td>
				    <td>Исполнитель:</td>
				    <td>
						<select name="executive_contract_{$contract.id}">
						{foreach from=$executives item=executive}
						    <option value="{$executive.id}" {if $contract.executive_id==$executive.id}selected{/if}>{$executive.executive_name|sslash}</option>
						{/foreach}
						</select>
				    </td>
				    <td>&nbsp;<a href="contract-delete.php?id={$contract.id}" class="contact-delete"><img src="images/icons/delete_16.png" border="0"/></a></td>
				</tr>
				{/foreach}
				<tr class="contract-row">
				    <td>Номер договора:</td>
				    <td><input size="10" type="text" name="contract_num[]"/></td>
				    <td>Дата заключения:</td>
				    <td><input type="text" name="date_contract[]" class="date"/></td>
				    <td>Дата окончания:</td>
				    <td><input type="text" name="date_contract_end[]" class="date"/></td>
				    <td>Исполнитель:</td>
				    <td>
					<select name="executive_contract[]">
					    <option value="">Исполнитель</option>
					{foreach from=$executives item=executive}
					    <option value="{$executive.id}">{$executive.executive_name}</option>
					{/foreach}
					</select>
				    </td>
				    <td colspan="5" align="right"></td>
				</tr>
				<tr>
					<td colspan="13" align="right"><a href="javascript:void(0)" id="contract-add"><img src="images/icons/plus_16.png" border="0"/>Добавить договор</a></td>
				</tr>
				{foreach from=$arbitrary_fields item=field}
				<tr class="arbitrary-row">
				    <td colspan="2" align="right">{$field.field_name}:</td>
				    <td><input size="10" type="text" name="arbitrary_field_{$field.field_id}" value="{$field.value|sslash|escape}"/></td>
				    <td colspan="2"><a href="arbitrary-delete.php?id={$field.field_id}"><img src="images/icons/delete_16.png" border="0"/></a></td>
				    <td colspan="4">&nbsp;</td>
				    <td colspan="3" align="right"></td>
				</tr>
				{/foreach}
				<tr class="arbitrary-row">
				    <td colspan ="2" align="right">
						<select name="arb_field_name_id[]">
						{foreach from=$customer_fields item=field}
					    	{if $field.id>0}<option value="{$field.id}">{$field.title}</option>{/if}
						{/foreach}
						</select>
				    </td>
				    <td colspan="8"><input size="10" type="text" name="arbitrary_field[]"/></td>
				    <td colspan="3" align="right"></td>
				</tr>
				<tr>
				    <td colspan="2" align="right"><a href="javascript:void(0)" id="arbitrary-add"><img src="images/icons/plus_16.png" border="0"/>Добавить поле</a></td>
				    <td colspan="8">&nbsp;</td>
				    <td colspan="3" align="right"></td>
				</tr>
				{if $managers!=''}
				<tr>
					<td align="right"><a href="javascript:void(0)" id="manage-managers"><img src="images/icons/address_16.png" border="0"/></a></td>
				    <td align="right">
						Менеджер:
				    </td>				    
				    <td colspan="8">
					<select name="manager" id="manager-select">
					{foreach from=$managers item=manager}
					    {if $customer!=''}
					    <option value="{$manager.id}" {if $manager.id==$customer.manager_id}selected{/if}>{$manager.manager_name}</option>
					    {else}
					    <option value="{$manager.id}" {if $manager.id==$session.manager.id}selected{/if}>{$manager.manager_name}</option>
					    {/if}
					{/foreach}
					</select>
				    </td>
				    <td colspan="3" align="right"></td>
				</tr>
				{/if}
				<tr>
				    <td align="right">E-Mail:</td>
				    <td colspan="2"><input type="text" name="email" value="{$customer.email}"/></td>
				    <td align="right">Пароль:</td>
				    <td colspan="6">
					<input type="text" name="email_password" id="email-password" value="{$customer.password}"/>
					<a href="javascript:void(0)" id="password-generate"><img src="images/icons/key_16.png" border="0" title="Сгенерировать пароль"/></a>
				    </td>
				    <td colspan="3">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="13">&nbsp;</td>
				</tr>
				{if $groups!=''}
				<tr>
				    <td align="right">
						<a href="javascript:void(0)" id="manage-groups"><img src="images/icons/address_16.png" border="0"/></a>
						Группа:
				    </td>
				    <td colspan="9">
						<select name="group" id="select-group">
						{foreach from=$groups item=group}
					    	<option value="{$group.id}" {if $customer.group_id==$group.id}selected{/if}>{$group.group_name}</option>
						{/foreach}
						</select>
				    </td>
				    <td colspan="3" align="right"></td>
				</tr>
				{/if}

				{if is_array($statuses)}
				<tr>
				    <td align="right">
						<a href="javascript:void(0)" id="manage-statuses"><img src="images/icons/address_16.png" border="0"/></a>
						Статус:
				    </td>
				    <td colspan="9">
						<select name="status" id="select-status">
						{foreach from=$statuses item=status}
					    	<option value="{$status.id}" {if $customer.status_id==$status.id}selected{/if}>{$status.status_name}</option>
						{/foreach}
						</select>
				    </td>
				    <td colspan="3" align="right"></td>
				</tr>
				{/if}
			    </table>

			    {if is_array($customer)}
			    <hr/>
			    Обращения по телефону:
			    <table class="ui-widget ui-corner-top" width="100%" cellspacing="0" rules="all" style="border: solid 1px #000000;">
				<thead class="ui-widget-header">
				    <tr>
					<th width="15%">Дата</th>
					<th width="20%">Направление звонка</th>
					<th>Примечание</th>
				    </tr>
				</thead>
				<tbody class="ui-widget-content">
				{foreach from=$treatments item=treatment name=treatments}
				    <tr {if $treatment.close==1}class="ui-state-disabled task-row"{elseif $treatment.this_is_task==1}class="ui-state-active task-row"{else}{if $treatment.direction=='incomming'}bgcolor="#f0f0ff"{/if}{/if}>
					<td><span style="display: none;">{$treatment.id}</span>{$treatment.date_time|date_format:'%d.%m.%Y, %H:%M'}</td>
					{if $treatment.this_is_task==1}
					<td><a href="task.php?id={$treatment.id}"><strong>Задача #{$treatment.id}</strong></a></td>
					{else}
					<td>{if $treatment.direction=='incomming'}Входящее{elseif $treatment.direction=='outgoing'}Исходящее{else}&mdash;{/if}</td>
					{/if}
					<td>{$treatment.note|sslash}</td>
				    </tr>
				{foreachelse}
				    <tr><td colspan="3" align="center">Обращений не найдено</td></tr>
				{/foreach}
				</tbody>
			    </table>
			    <br/>
			    <a href="javascript:void(0)" id="treatment-add"><img src="images/icons/plus_16.png" border="0"/>&nbsp;Создать обращение</a>
			    {/if}
			</div>
<!-- ВКЛАДКА Реквизиты -->
			<div id="bank">
			    <table width="100%">
				<tr>
				    <th colspan="2">Юридический адрес</th>
				</tr>
				<tr>
				    <td align="right">Регион:</td>
				    <td><input type="text" name="legal_region" id="legal-region" value="{$customer.legal_region}"/></td>
				</tr>
				<tr>
				    <td align="right">Город:</td>
				    <td><input type="text" name="legal_city" id="legal-city" value="{$customer.legal_city}"/></td>
				</tr>
				<tr>
				    <td align="right">Индекс:</td>
				    <td><input type="text" name="legal_index" id="legal-index" value="{$customer.legal_index}"/></td>
				</tr>
				<tr>
				    <td align="right">Улица:</td>
				    <td><input type="text" name="legal_street" id="legal-street" value="{$customer.legal_street}"/></td>
				</tr>
				<tr>
				    <td align="right">Дом:</td>
				    <td><input type="text" name="legal_home" id="legal-home" value="{$customer.legal_home}"/></td>
				</tr>
				<tr>
				    <td align="right">Литера:</td>
				    <td><input type="text" name="legal_litera" id="legal-litera" value="{$customer.legal_litera}"/></td>
				</tr>
				<tr>
				    <td align="right">Офис:</td>
				    <td><input type="text" name="legal_office" id="legal-office" value="{$customer.legal_office}"/></td>
				</tr>
				<tr>
				    <th colspan="2">Фактический адрес <input type="checkbox" id="match-jur"/><label for="match-jur">совпадает с юридическим</label></th>
				</tr>
				<tr class="address-actual">
				    <td align="right">Регион:</td>
				    <td><input type="text" name="actual_region" id="actual-region" value="{$customer.actual_region}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Город:</td>
				    <td><input type="text" name="actual_city" id="actual-city" value="{$customer.actual_city}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Индекс:</td>
				    <td><input type="text" name="actual_index" id="actual-index" value="{$customer.actual_index}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Улица:</td>
				    <td><input type="text" name="actual_street" id="actual-street" value="{$customer.actual_street}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Дом:</td>
				    <td><input type="text" name="actual_home" id="actual-home" value="{$customer.actual_home}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Литера:</td>
				    <td><input type="text" name="actual_litera" id="actual-litera" value="{$customer.actual_litera}"/></td>
				</tr>
				<tr class="address-actual">
				    <td align="right">Офис:</td>
				    <td><input type="text" name="actual_office" id="actual-office" value="{$customer.actual_office}"/></td>
				</tr>
				<tr>
				    <th colspan="2">
					Почтовый адрес <input type="checkbox" id="match"/><label for="match">совпадает с</label>
					<select id="postal-match" style="display:none;">
					    <option value="0">-</option>
					    <option value="jur">юридическим</option>
					    <option value="act">фактическим</option>
					</select>
				    </th>
				</tr>
				<tr class="address-postal">
				    <td align="right">Регион:</td>
				    <td><input type="text" name="postal_region" id="postal-region" value="{$customer.postal_region}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Город:</td>
				    <td><input type="text" name="postal_city" id="postal-city" value="{$customer.postal_city}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Индекс:</td>
				    <td><input type="text" name="postal_index" id="postal-index" value="{$customer.postal_index}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Улица:</td>
				    <td><input type="text" name="postal_street" id="postal-street" value="{$customer.postal_street}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Дом:</td>
				    <td><input type="text" name="postal_home" id="postal-home" value="{$customer.postal_home}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Литера:</td>
				    <td><input type="text" name="postal_litera" id="postal-litera" value="{$customer.postal_litera}"/></td>
				</tr>
				<tr class="address-postal">
				    <td align="right">Офис:</td>
				    <td><input type="text" name="postal_office" id="postal-office" value="{$customer.postal_office}"/></td>
				</tr>
				<tr>
				    <th colspan="2">Реквизиты</th>
				</tr>
				<tr>
				    <td align="right">ИНН:</td>
				    <td><input type="text" name="inn" id="bank-inn" value="{$customer.inn}"/></td>
				</tr>
				<tr>
				    <td align="right">КПП:</td>
				    <td><input type="text" name="kpp" id="bank-kpp" value="{$customer.kpp}"/></td>
				</tr>
				<tr>
				    <td align="right">ОКПО:</td>
				    <td><input type="text" name="okpo" id="bank-okpo" value="{$customer.okpo}"/></td>
				</tr>
				<tr>
				    <td align="right">ОКОНХ:</td>
				    <td><input type="text" name="okonh" id="bank-okonh" value="{$customer.okonh}"/></td>
				</tr>
				<tr>
				    <td align="right">БИК:</td>
				    <td><input type="text" name="bic" id="bank-bic" value="{$customer.bik}"/></td>
				</tr>
				<tr>
				    <td align="right">БАНК:</td>
				    <td><input type="text" name="bank_name" id="bank-name" value="{$customer.bank|sslash|escape}"/></td>
				</tr>
				<tr>
				    <td align="right">Р/С:</td>
				    <td><input type="text" name="account_r" id="bank-account-r" value="{$customer.current_account}"/></td>
				</tr>
				<tr>
				    <td align="right">К/С:</td>
				    <td><input type="text" name="account_k" id="bank-account-k" value="{$customer.korr_account}"/></td>
				</tr>
			    </table>
			    </form>
			</div>
			{if is_array($customer)}

<!-- ВКЛАДКА Услуги -->
			<div id="services">
			{include file="admin/submodules/services.tab.html"}
			</div>

<!-- ВКЛАДКА Контакты -->
			<div id="contact">
			{include file="admin/submodules/contacts.tab.html"}
			</div>
			{/if}

			{if is_array($customer)}
<!-- ВКЛАДКА Документы -->
			<div id="document">
			{include file="admin/submodules/documents.tab.html"}
			</div>

<!-- ВКЛАДКА Счета -->
			<div id="invoice">
			{include file="admin/submodules/invoices.tab.html"}
			</div>

			    {if $contracts|@count>0}
			<div id="payment">
			{include file="admin/submodules/payment.tab.html"}
			</div>

			<div id="verification-act">
			{include file="admin/submodules/ver_act.tab.html"}
			</div>
			    {/if}
			{/if}
		    </div>
		</td>
	    </tr>
	</table>
	<script type="text/javascript">
	<!--{literal}
	$(document).ready(function(){$('body').show();});
	{/literal}-->
	</script>
    </body>
</html>
